package com.example.zyfypt_206shj.model;

import com.example.zyfypt_206shj.bean.TcaseBean;
import com.example.zyfypt_206shj.bean.VideoBean;
import com.example.zyfypt_206shj.iface.TcaseListener;
import com.example.zyfypt_206shj.iface.Tcaseiface;
import com.example.zyfypt_206shj.iface.VideoListener;
import com.example.zyfypt_206shj.iface.Videoiface;
import com.example.zyfypt_206shj.service.TcaseService;
import com.example.zyfypt_206shj.service.VideoService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Raindy on 2017/4/22.
 */

public class VideoModel implements Videoiface {
    private Retrofit retrofit;
    private String BASEURL = "http://amicool.neusoft.edu.cn/";

    //构造方法
    public VideoModel(){
        retrofit = new Retrofit.Builder().baseUrl(BASEURL).addConverterFactory(GsonConverterFactory.create()).build();
    }

    //获取文章数据
    @Override
    public void getResultList(String mod, int page, String sessionID, final VideoListener listener) {
        VideoService videoService = retrofit.create(VideoService.class);
        Call<List<VideoBean>> call = videoService.getResult(mod, page, sessionID);
        call.enqueue(new Callback<List<VideoBean>>() {
            @Override
            public void onResponse(Call<List<VideoBean>> call, Response<List<VideoBean>> response) {
                if(response.isSuccessful() && response.body() != null){
                    listener.onResponse(response.body());
                } else {
                    listener.onFail("on response fail");
                }
            }

            @Override
            public void onFailure(Call<List<VideoBean>> call, Throwable t) {

            }
        });
    }
}
